/**
 *  Copyright (C) 2010:
 *                 Buzzanca Marco <marco.bzn@gmail.com>
 *         Monaco Davide Giuseppe <black.ralkass@gmail.com>
 *              Petralia Veronica <veronicapetralia@gmail.com>
 *
 * This file is part of DS2011BMP
 *
 * DS2011BMP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DS2011BMP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * @file tqueuemanagerproxy.h
 * @author Davide Giuseppe Monaco
 *
 * This header file contains TQueueManagerProxy class declaration.
 */

#ifndef _T_QUEUE_MANAGER_PROXY_H_
#define _T_QUEUE_MANAGER_PROXY_H_ 1

#include "address.h"
#include "udpclient.h"

/**
 * @brief TQueueManagerProxy handles communication with TQueueManager.
 *
 * In order to communicate with a Worker, a Manager needs a TQueueManagerProxy.
 * Manager-Worker interaction consist in enqueue() call.<br />
 * Through enqueue() a Manager is able to push into Worker TaskDescriptor queue
 * a new element.<br />
 * TQueueManagerProxy uses an UDPClient to send enqueue() requests.
 */
class TQueueManagerProxy
{
private:
  /**
   * @brief Worker Address.
   */
  Address _addr;

  /**
   * @brief The UDP client that TQueueManagerProxy will use to contact the Worker.
   */
  UDPClient _c;

public:
  /**
   * @brief Default Constructor.
   *
   * @note This should not be used.
   */
  TQueueManagerProxy(void);

  /**
   * @brief Constructor specifying server Address.
   * @param addr Server Address.
   */
  TQueueManagerProxy(const Address& addr);

  /**
   * @brief Destructor.
   */
  ~TQueueManagerProxy(void);

  /**
   * @brief Returns the current Worker Address.
   * @return  A constant reference to private member _addr.
   */
  const Address& getAddr(void) const;

  /**
   * @brief Sets current Worker Address to the provided Address.
   * @param addr   The provided Address.
   */
  void setAddr(const Address& addr);

  /**
   * @brief Sets current Manager Address to the provided IP and port.
   * @param IP    Server IP address.
   * @param port  Server port.
   */
  void setAddr(const std::string& IP, boost::uint16_t port);

  /**
   * @brief Ask the Worker to add provided TaskDescriptor into its queue.
   *
   * This method sends the provided TaskDescriptor to TQueueManager module
   * via UDP, using boost asio and serialization utilities.
   *
   * @note As long as the service offered is best effort in this stage of
   * development no delivery warranties are provided.
   *
   * @param ts     The provided TaskDescriptor.
   * @return       Zero if operation successful, otherwise an error code.
   */
  int enqueue(const TaskDescriptor& ts);
};

#endif /* _T_QUEUE_MANAGER_PROXY_H_ */
